﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WWWSiteHelper
{
    public partial class NewFileDialog : Form
    {
        MainForm mainForm;
        public NewFileDialog()
        {
            mainForm = (MainForm)this.Owner;
            InitializeComponent();
            foreach (var type in System.Enum.GetValues(typeof(AbstractFile.FileType)))
            {
                typeComboBox.Items.Add(type);
            }
            typeComboBox.SelectedIndex = 0;
        }

        private void viewUpdate(object sender, EventArgs e)
        {
            if (nameTextBox.Text.Equals(""))
                okButton.Enabled = false;
            else
                okButton.Enabled = true;
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            MainForm mainForm = (MainForm)this.Owner;
            AbstractFile.FileType type = (AbstractFile.FileType)typeComboBox.SelectedItem;
            AbstractFile file = new AbstractFile(nameTextBox.Text, type, mainForm.CurrentProject.Id);
            if (mainForm.CurrentProject.Contains(file))
            {
                MessageBox.Show("Plik o podanej nazwie już istnieje!", "Błąd tworzenia pliku", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            mainForm.CurrentProject.AddFile(file);
            mainForm.tabObservator.SetContext(file);
            mainForm.UpdateProjectStatus();
            Close();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
